/**
 * 处理请求和ajax
 * @type {Function}
 */
var RequestData = (function( par ){

    function RequestData( object ){

        this.request = {
            head : {
                token: "Web",
                openid: "fenxiao",
                client: "Web",
                //uid: obj.head.uid ?  obj.head.uid   : '',
                versionCode: "1.0.0",
                deviceCode: "web",
                crossDomain: "cross_domain",
                otherParameters:""
            },
            body : {}
        };

        $.extend(true,this.request,object );

    }

    var jsonString = function (o) {
        var str = JSON.stringify(o);
        return str;
    };
    RequestData.prototype.getAjax = function( obj ) {
        var self = this;
        // console.log(self.request);
        var head = self.request.head;
        head.crossDomain="";
        $.ajax({
            url: obj.url.replace("?msg=","") ,
            data:{},
            type:"POST",
            data:{msg:jsonString({head:head,body:self.request.body})},
            // dataType: "jsonp",
            // jsonp: "callback",
            //自定义的jsonp回调函数名称"jsonpCallback"，返回的json也必须有这个函数名称
            //  jsonpCallback:  self.request.head.crossDomain,
            success: function (data) {

                if(data.head.code === 0 && data.head.errorCode === "10001"){
                     window.location="/api/store/page/login";
                    $.toast("请先登录!");
                    if(obj.url.indexOf("/api/store/shipping/address/default")!=-1){
                        window.location="/api/store/page/login";
                    }
                    if( obj.success ){
                        obj.success( data);
                    }else{
                        obj.success = new Function(data);
                    }
                }else if(data.head.code === 0 && data.head.errorCode === "111"){

                    $.alert(data.head.message);
                }else{
                    if( obj.success ){
                        obj.success( data);
                    }else{
                        obj.success = new Function(data);
                    }
                }

            },
            error : function( XMLHttpRequest, textStatus, errorThrown ) {
                if(obj.error ){
                    obj.error( XMLHttpRequest, textStatus, errorThrown );
                }else{
                    obj.error = new Function(XMLHttpRequest, textStatus, errorThrown)
                }
            }
        });
    };


    return  new RequestData(par);
});







/**
 * url集合
 * @returns {{loginUrl: string, registerUrl: string, getPhoneCode: string, updatePsd: string, addressList: string, addressAdd: string, addressDefault: string, addressDelete: string, addressSetDefault: string, addressUpdate: string, addressEdit: string, addressGetDefault: string, unifiedOrder: string, orderInfo: string, orderList: string, odersGoods: string, ordersLog: string, ordersRefund: string, ordersDelete: string, uploadImageUrl: string, orderPayEwm: string, passwordEdit: string, getUserInfo: string, userInfoEdit: string}}
 */
function  urlGathers(){

    var host = getHost();
    var url = {


        messageDetail:host+"/api/store/message/detail?msg=",
        messageList:host+"/api/store/message/list?msg=",
        bannerList:host+"/api/store/index/banner/list?msg=",
        /**
         * 商品轮询图片列表
         */
        goodsBannerList:host+"/api/store/goods/banner/list?msg=",
        commentList:host+"/api/store/comment/list?msg=",
        commentGoods:host+"/api/store/comment/goods?msg=",
        /**
         * 添加评论
         */
        addComment:host+"/api/store/comment/add?msg=",
        /**
         * 登录地址
         * @type {string}
         */
        loginUrl: host + "/api/store/login?msg=",

        login : host + "/api/store/login/code?msg=",

        applyTaster : host + "/api/store/taster/apply?msg=",

        toTasterSystemUrl : host + "/api/store/taster/system?msg=",

        /**
         * 商品列表
         * @type {string}
         */
        goodsList : host + "/api/store/goods/list?msg=",

        // 热销商品
        hotGoods : host + "/api/store/goods/list/hot?msg=",

        // 产品信息
        goodsInfor : host + "/api/store/goods/info?msg=",

        // 添加到购物车
        addCard : host + "/api/store/buy/card/add?msg=",

        //
        saveCard : host + "/api/store/buy/card/save?msg=",

        // 商品详情
        goodsDetails :host + "/api/store/goods/detail",

        // 购物车列表
        cartList : host + "/api/store/buy/card/list?msg=",

        cartNumber : host + "/api/store/common/info/bcnumber?msg=",

        //  删除购物车
        deleteCart : host + "/api/store/buy/card/delete?msg=",

        // 购物车下单
        cartPay :  host + "/api/store/order/fenxiao/make/card?msg=",

        // 直接下单支付
        dirtPay :  host + "/api/store/order/fenxiao/make?msg=",

        // 确认收货
        confirmGoods : host + "/api/proxy/store/order/take/over?msg=",

        // 退货

        applyRefundGoods : host +  "/api/store/order/refund/goods/apply?msg=",

        // 完善退货信息
        postLogistics: host + "/api/store/order/refund/goods/update?msg=",

        // 取消退货
        cancelRefund: host + "/api/store/order/refund/goods/cancel?msg=",


        // 意见反馈

        feedback : host + "/api/school/feedback/add?msg=",

        // 常见问题
        questionList : host + "/api/store/question/list?msg=",

        // 问题详情
        questionDetail: host + "/api/store/question/detail?msg=",

        // 绑定、修改手机号
        mobileBind: host + "/api/store/phone/bind?msg=",












        /**
         * 注册地址
         * @type {string}
         */
        registerUrl: host + "/api/store/register?msg=",

        /**
         * 获取验证码地址
         * @type {string}
         */
        getPhoneCode: host + "/api/store/verification/code/get?msg=",

        /**
         * 修改密码地址
         * @type {string}
         */
        updatePsd: host + "/api/store/user/password/update?msg=",

        /**
         * 收货
         * @type {string}
         */
        addressList: host + "/api/store/shipping/address?msg=",

        /**
         * 添加收货
         * @type {string}
         */
        addressAdd: host + "/api/store/shipping/address/save?msg=",

        /**
         * 默认收货
         * @type {string}
         */
        addressDefault: host + "/api/store/shipping/address/default?msg=",

        /**
         * 删除收货地址
         *
         */
        addressDelete: host + "/api/store/shipping/address/delete?msg=",

        /**
         * 设置默认收货地址
         */
        addressSetDefault: host + "/api/store/shipping/address/default/set?msg=",

        /**
         * 修改收货地址
         */
        addressUpdate: host + "/api/store/shipping/address/update?msg=",

        /**
         * 收货地址详情
         */
        addressGetInfo: host + "/api/store/shipping/address/info?msg=",


        /**
         * 获取默认收货地址
         */
        addressGetDefault: host + "/api/store/shipping/address/default?msg=",


        /**
         * 下单
         * @type {string}
         */
        unifiedOrder: host + "/api/store/order/unifiedorder?msg=",

        /**
         * 订单详情
         * @type {string}
         */
        orderInfo: host + "/api/store/order/info?msg=",

        /**
         * 订单列表
         */
        orderList: host + "/api/store/order/list?msg=",

        /**
         * 订单商品 列表
         * @type {string}
         */
        odersGoods: host + "/api/store/order/goods?msg=",

        /**
         * 订单操作日志
         * @type {string}
         */
        ordersLog: host + "/api/store/order/log?msg=",

        /**
         * 订单取消
         */
        ordersRefund: host + "/api/store/order/refund?msg=",

        /**
         *
         */
        ordersDelete: host + "/api/store/order/delete?msg=",

        /**
         * 获取退款信息
         */
        getRefundDetail: host + "/api/store/order/refund/goods/detail?msg=",


        /**
         *
         */
        getRefundLog: host + "/api/store/order/refund/log?msg=",








        /**
         * 上传图片
         */
        uploadImageUrl: host + "/api/file/upload?msg=",


        orderPayEwm: host + "/api/store/order/pay/wx/qrcode?msg=",


        /**
         * 修改密码
         */
        passwordEdit: host + "/api/store/user/password/update?msg=",

        /**
         * 获取用户基本信息
         */
        getUserInfo: host + "/api/store/proxy/info?msg=",

        /**
         * 修改基本信息
         */

        userInfoEdit: host + "/api/store/proxy/info/update?msg="
    };

    return url;

}
var urlGather = urlGathers();




function login(obj,callback){

    var login = {
        url : urlGather.login,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_login"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( login );
}



/**
 * 个人信息处理函数集合
 */

/**
 * 修改密码
 * @param obj
 * @param callback
 */

function editPassword( obj,callback ){
    var passwordEdit = {
        url : urlGather.passwordEdit,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_editpsd"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( passwordEdit );

}




/**
 * 获取验证码
 * @param obj    传到服务器的参数
 * @param callback    回调函数，处理返回的数据
 */

function getVerifyCode(obj,callback){

    var getPhoneCode = {
        url : urlGather.getPhoneCode,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_getPhoneCode"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( getPhoneCode );


}

/**
 * 获取个人信息
 * @param callback
 */
function getUserInfor(obj,callback){

    var getUserInfo = {
        url : urlGather.getUserInfo,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_getUserInfo"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( getUserInfo );
}


/**
 * 申请品鉴师
 * @param callback
 */

function applyTaster(obj,callback){

    var apply = {
        url : urlGather.applyTaster,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "taster_apply"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( apply);
}



function tomTasterSystem(obj,callback){

    var apply = {
        url : urlGather.toTasterSystemUrl,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "taster_check"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( apply);

}




function editUserInfo( obj,callback ){

    var userInfoEdit = {
        url: urlGather.userInfoEdit ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    }

    var objects = {
        head : {
            crossDomain : "cross_userInfoEdit"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( userInfoEdit );

}






var judgeOrderState = {
    normal : {
        notPay: "000",
        waltGood : "100",
        shipped : "110",
        received : "120"
    },
    cancel:{
        canceled: "200"
    },
    refund:{
        checking: "1",
        checkpass: "2",
        cancelRefund:"3",
        checkNotPass:"4",
        receiptSuring:"5",
        complete:"6"
    },

    check : {
        1 : "申请已提交",
        2 : "申请通过",
        3 : "取消申请",
        4 : "退款完成"
    }



}

function is_refund(state){

    var s = state.substr(2,1);

    if( s == "2" ){
        return true;
    }else{
        return false;
    }

}

function is_stocking(state){
    var s = state.substr(2);
    if( s == "3" ){
        return true;
    }else{
        return false;
    }
}


/**
 *
 */

function getGoodsList(obj,callback){
    var goodsList = {
        url : urlGather.goodsList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };

    var objects = {
        head : {
            crossDomain : "cross_goodsList"
        }
    };


    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( goodsList );
}

// 热销商品
function getHotGoodsList(obj,callback){
    var hotGoods = {
        url : urlGather.hotGoods,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };

    var objects = {
        head : {
            crossDomain : "cross_hotGoods"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( hotGoods );
}



/**
 * 获取商品详情
 * @param obj
 * @param callback
 */
function getGoodsInfor(obj,callback){
    var goodsInfor = {
        url : urlGather.goodsInfor,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };

    var objects = {
        head : {
            crossDomain : "cross_goodsInfor"
        }
    };


    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( goodsInfor );
}


/**
 * 添加到购物车
 * @param obj
 * @param callback
 */
function addGoodCard(obj,callback){
    var addCard = {
        url : urlGather.addCard,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_addCard"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addCard );
}


function operateGooodsNumber(obj,callback){
    var saveCard = {
        url : urlGather.saveCard,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_saveCard"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( saveCard );
}







/**
 * 获取购物车列表
 * @param obj
 * @param callback
 */
function getCartList(obj,callback){
    var cartList = {
        url : urlGather.cartList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_cartList"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartList );
}

function getCartNumber(obj,callback){
    var cartNumber = {
        url : urlGather.cartNumber,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_cartNumber"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartNumber );
}






function deleteCart(obj,callback){
    var deleteCart = {
        url : urlGather.deleteCart,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_deleteCart"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( deleteCart );
}




/**
 * 获取商品详情
 * @param url
 * @param obj
 * @param callback
 */
function getGoodsDetails(url,obj,callback){
    var addCard = {
        url : urlGather.goodsDetails + url,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_goodsDetails"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addCard );
}


/**
 * 购物车下单
 * @param obj
 * @param callback
 */
function placeCartOrder(obj,callback){
    var cartPay = {
        url : urlGather.cartPay,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_cartPay"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}


/**
 * 直接下单
 * @param obj
 * @param callback
 */
function placeDirOrder(obj,callback){
    var dirtPay = {
        url : urlGather.dirtPay,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_dirtPay"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( dirtPay );
}



function placeOrder(url,obj,callback){
    var dirtPay = {
        url : getHost() + url + "?msg=",
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_placeOrder"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( dirtPay );
}










function buildDirOrder(obj,callback){
    var onlyUrl = {
        url : urlGather.onlyUrl,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_onlyUrl"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( onlyUrl );
}

function getEarnings(obj,callback){
    var earnings = {
        url : urlGather.earnings,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_earnings"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( earnings );
}


function getAdvStats(obj,callback){
    var advStats = {
        url : urlGather.advStats,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_advStats"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( advStats );
}



function getWithdraw(obj,callback){
    var withdraw = {
        url : urlGather.withdraw,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_withdraw"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( withdraw );
}

function confirmGoods(obj,callback){

    var confirmGoods = {
        url : urlGather.confirmGoods,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_confirmGoods"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( confirmGoods );
}



function applyRefundGood(obj,callback){

    var applyRefundGoods = {
        url : urlGather.applyRefundGoods,
        success : function(data){
            callback(data);
        },
        error:function(){
        }
    };
    var objects = {
        head : {
            crossDomain : "cross_applyRefundGoods"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( applyRefundGoods );
}

function toFeedback(obj,callback){

    var feedback = {
        url : urlGather.feedback,
        success : function(data){
            callback(data);
        },
        error:function(){
        }
    };
    var objects = {
        head : {
            crossDomain : "cross_feedback"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( feedback );
}


function toQuestionList(obj,callback){

    var questionList = {
        url : urlGather.questionList,
        success : function(data){
            callback(data);
        },
        error:function(){
        }
    };
    var objects = {
        head : {
            crossDomain : "cross_questionList"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( questionList );
}


function getQuestionDetail(obj,callback){

    var questionDetail = {
        url : urlGather.questionDetail,
        success : function(data){
            callback(data);
        },
        error:function(){
        }
    };
    var objects = {
        head : {
            crossDomain : "cross_questionDetail"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( questionDetail );
}



/**
 * 绑定、修改手机号
 * @param obj
 * @param callback
 */
function bindMobile(obj,callback){
    var mobileBind = {
        url: urlGather.mobileBind ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };

    var objects = {
        head : {
            crossDomain : "cross_mobileBind"
        }
    };

    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( mobileBind );
}


/**
 * 可评论商品
 * @param obj
 * @param callback
 */
function canCommentGoods(obj,callback){
    var cartPay = {
        url : urlGather.commentGoods,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_canComment"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}
/**
 * 消息详情
 * @param obj
 * @param callback
 */
function messageDetail(obj,callback){
    var cartPay = {
        url : urlGather.messageDetail,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "messageDetail"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}
/**
 * 消息列表
 * @param obj
 * @param callback
 */
function messageList(obj,callback){
    var cartPay = {
        url : urlGather.messageList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "listMessage"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}
/**
 * 评论列表
 * @param obj
 * @param callback
 */
function commentList(obj,callback){
    var cartPay = {
        url : urlGather.commentList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "listComment"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}
/**
 * banner列表
 * @param obj
 * @param callback
 */
function bannerList(obj,callback){
    var cartPay = {
        url : urlGather.bannerList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "bannerList"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}

/**
 * goods banner列表
 * @param obj
 * @param callback
 */
function goodsBannerList(obj,callback){
    var cartPay = {
        url : urlGather.goodsBannerList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "goodsBannerList"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}



/**
 * 添加评论
 * @param obj
 * @param callback
 */
function addComment(obj,callback){
    var cartPay = {
        url : urlGather.addComment,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_addComment"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cartPay );
}

/**
 *
 * @param obj
 * @param callback
 */
function updateRefundMsg(obj,callback){

    var postLogistics = {
        url : urlGather.postLogistics,
        success : function(data){
            callback(data);
        },
        error:function(){
        }
    };
    var objects = {
        head : {
            crossDomain : "cross_postLogistics"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( postLogistics );
}

/**
 * 取消退货
 * @param obj
 * @param callback
 */
function cancelRefund(obj,callback){

    var cancelRefund = {
        url : urlGather.cancelRefund,
        success : function(data){
            callback(data);
        },
        error:function(){
        }
    };
    var objects = {
        head : {
            crossDomain : "cross_cancelRefund"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( cancelRefund );
}



function goIdentify(obj,callback){
    var identify = {
        url : urlGather.identify,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_identify"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( identify );
}



/**
 * 订单处理函数集合
 */


/**
 * 取消订单操作
 * @param orderId     订单Id
 * @param callback    回调函数，处理返回的数据
 */
function cancelOrder(orderId,callback){


    var ordersRefund = {
        url : urlGather.ordersRefund,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    }
    var obj = {
        head : {
            crossDomain : "cross_cancel"
        },
        body : {
            orderId :orderId
        }

    }
    var req = RequestData( obj );
    req.getAjax( ordersRefund );

}


/**
 * 取消订单
 * @param obj
 * @param callback
 */
function cancelOrders(obj,callback){
    var ordersRefund = {
        url : urlGather.ordersRefund,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };

    var objects = {
        head : {
            crossDomain : "cross_cancelOrders"
        }
    };


    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( ordersRefund );

}





/**
 * 申请退款
 * @param obj
 * @param callback
 */

function applyRefund(obj,callback){

    var ordersRefund = {
        url : urlGather.ordersRefund,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    }

    var objects = {
        head : {
            crossDomain : "cross_applyRefund"
        }
    };


    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( ordersRefund );

}


/**
 * 删除订单操作
 * @param orderId
 * @param callback
 */
function deleteOrder(orderId,callback){


    var ordersDelete = {
        url : urlGather.ordersDelete,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var obj = {
        head : {
            crossDomain : "cross_delete"
        },
        body : {
            orderId :orderId
        }

    }
    var req = RequestData( obj );
    req.getAjax( ordersDelete );




}

/**
 * 订单详情 -- 获取订单详情信息
 * @param obj    请求参数
 * @param callback    回调函数，处理数据
 */

function getOrdersDetail(obj,callback){
    var orderInfo = {
        url : urlGather.orderInfo ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };
    var objects = {
        head : {
            crossDomain : "cross_orderInfor"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( orderInfo );
}


/**
 * 获取订单列表
 * @param obj
 * @param callback
 */
function getOderLists(obj,callback){

    var orderList = {
        url : urlGather.orderList,
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    }
    var objects = {
        head : {
            crossDomain : "cross_orderList"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( orderList );

}




/**
 * 获取退款信息
 * @param obj
 * @param callback
 */
function getRefundState(obj,callback){
    var getRefundDetail = {
        url : urlGather.getRefundDetail ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };
    var objects = {
        head : {
            crossDomain : "cross_getRefundDetail"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( getRefundDetail );

}


function getRefundLog(obj,callback){
    var getRefundLog = {
        url : urlGather.getRefundLog ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };
    var objects = {
        head : {
            crossDomain : "cross_getRefundLog"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( getRefundLog );
}




/**
 * 收货地址处理函数
 */



/**
 * 保存收货地址
 * @param obj
 * @param callback
 */
function saveAddress(obj,callback){

    var addressAdd = {
        url : urlGather.addressAdd ,
        success : function(data){
            callback(data);
        },
        error : function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_delete"
        }
    }

    objects.body = obj.body ? obj.body : {};

    var req = RequestData( objects );
    req.getAjax( addressAdd );
}






/**
 * 获取物流信息
 * @param obj
 * @param callback
 */
function getTransportLog(obj,callback){

    var ordersLog = {
        url : urlGather.ordersLog ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };
    var objects = {
        head : {
            crossDomain : "cross_transport"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( ordersLog );

}

/**
 * 获取默认地址
 * @param obj
 * @param callback
 */
function getAddressDefault(obj,callback){
    var addressGetDefault = {
        url : urlGather.addressGetDefault ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };
    var objects = {
        head : {
            crossDomain : "cross_getDefault"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addressGetDefault );
}

/**
 * 确认订单
 * @param obj
 * @param callback
 */
function sureAddress( obj,callback ){

    var unifiedOrder = {
        url : urlGather.unifiedOrder,
        success : function( data ){

            callback( data );

        },
        error : function(){

        }
    }
    var objects = {
        head : {
            crossDomain : "cross_unifiedOrder"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( unifiedOrder );

}





/**
 * 获取收货地址列表
 * @param callback    回调函数，处理返回的数据
 */
/*function  getAddressList(callback){
 // 收货地址列表
 var addressList = {
 url : urlGather.addressList ,
 success : function(data){
 callback( data );
 },
 error : function(){

 }
 };
 getAjax(addressList);

 }*/


/**
 * 获取收货地址列表
 * @param obj
 * @param callback
 */
function  getAddressList(obj,callback){
    // 收货地址列表
    var addressList = {
        url : urlGather.addressList ,
        success : function(data){
            callback( data );
        },
        error : function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_addressList"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addressList );

}


/**
 * 获取收货地址详情
 * @param obj
 * @param callback
 */
function getAddressInfo(obj,callback){

    var addressGetInfo = {
        url: urlGather.addressGetInfo ,
        success: function(data){

            callback(data);

        },
        error : function(){

        }
    }

    var objects = {
        head : {
            crossDomain : "cross_addressGetInfo"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addressGetInfo );


}

/**
 * 修改收货地址
 * @param obj
 * @param callback
 */
function addressUpdate(obj,callback){

    var addressUpdate = {
        url:urlGather.addressUpdate,
        success: function(data){
            callback(data);
        },
        error:function(){}
    }

    var objects = {
        head : {
            crossDomain : "cross_addressUpdate"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addressUpdate );



}




/**
 * 收货地址设置默认地址
 * @param addressId        // 参数 地址ID
 */


function addressSetDefault( obj,callback ){

    var addressSetDefault = {
        url : urlGather.addressSetDefault ,
        success : function(data){
            callback(data);
        },
        error : function(){

        }
    };

    var objects = {
        head : {
            crossDomain : "cross_addressSetDefault"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addressSetDefault );
}









/**
 * 删除收货地址
 * @param obj
 * @param callback
 */
function addressDelete(obj,callback){

    var addressDelete = {
        url : urlGather.addressDelete ,
        success : function(data){
            callback(data);
        },
        error : function(){}
    };
    var objects = {
        head : {
            crossDomain : "cross_addressDelete"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( addressDelete );
}









/**
 * 页面结构生成函数集合
 */


/**
 * 订单确认 -- 单一收货地址生成 -- 存在默认地址的情况
 * @param data
 * @returns {string}
 * @constructor
 */

function AddressValInOk( data ){

    var html='';

    html+='<div class="orders-add-addr">';
    html+='<h3 class="addr-add-btn">收货地址 <span class="addr-add-point right"> </span> </h3>';
    html+='</div>';

    html+='<div class="orders-address-infor">';
    html+='<dl class="orders-address-inforlist" data-attr="' + data.body.addressId + '">';
    html+='<dt>收货人：</dt>';
    html+='<dd >' + data.body.consignee + ' <span  class="address-phone">'+ data.body.phone +'</span>';
    html+='</dd>';
    html+=' <dt>收货地址：</dt>';
    html+='<dd class="address-addr">'+ data.body.province + data.body.city + data.body.county + data.body.address +'</dd>';
    html+='<dt>邮政编码：</dt>';
    html+='<dd class="address-postCode">'+ data.body.postCode +'</dd>';
    html+='</dl>';
    html+='</div>';

    return html;


}

/**
 * 订单确认 -- 单一收货地址生成 -- 不存在默认地址的情况
 * @param data
 * @returns {string}
 * @constructor
 */
function addressValInNot( data ){
    var html='';
    html+='<div class="orders-add-addr">';
    html+='<h3 class="addr-add-btn"><img src="../images/orders/addr.png" />添加新地址 <span class="addr-add-point right">  </span> </h3>';
    html+='</div>';

    return html;

}





/**
 * 收货地址列表页面 -- 收货地址列表生成函数
 * @param data
 * @returns {string}
 */
function getContent(data){
    var html="";
    for( var i = 0; i < data.body.length;i++){
        html+= '<div class="orders-address-item" data-addId="' + data.body[i].addressId + ' " >';
        html+= '<div class="orders-address-infor">';
        html+= '<dl class="orders-address-inforlist">';
        html+= '<dt>收货人：</dt>';
        html+= '<dd class=""><em class="addr-name">'+ data.body[i].consignee + '</em><span class="addr-phone">' + data.body[i].phone + '</span></dd>';
        html+= '<dt>收货地址：</dt>';
        html+= '<dd class="addr-detail">' + data.body[i].province + data.body[i].city + data.body[i].county + data.body[i].address + '</dd>';
        html+= '</dl>';
        html+= '<span style="display:none" class="addr-postcode">' + data.body[i].postCode + '</span>'
        html+= '</div>';
        html+= '<div class="orders-address-operate">';
        html+= '<span class="orders-addr-default ' + (data.body[i].defaultAddress == 1 ? 'active' : '')  + ' " >' + '<i class=""></i>默认地址</span>';
        html+= '<div class="orders-addroper-state right">';
        html+= '<span class="orders-addroper-edit"><i></i>编辑</span>';
        html+= '<span class="orders-addroper-delete"><i></i>删除</span>';
        html+= '</div></div></div>';
    }

    return html;
}










/**
 * 订单详情 -- 生成订单信息
 * @param data
 * @returns {string}
 */
function getStateOrderInfo(data){
    var html="";
    html+='<div class="orders-details-orderinfor">';
    html+='<div class="details-orderinfor-number">';
    html+='<span >订单号：' + data.body.orderNumber + '</span>';
    html+='<span class="orderinfor-time">' + data.body.createTime + '</span>';
    html+='</div>';
    html+='</div>';
    html+='<div class="orders-address-infor">';
    html+=' <dl class="orders-address-inforlist">';
    html+='<dt>收货人：</dt>';
    html+='<dd> ' + data.body.shippingAddress.consignee + ' <span class="address-phone">'+ data.body.shippingAddress.phone +'</span></dd>';
    html+='<dt>收货地址：</dt>';
    html+='<dd class="address-addr">'+ data.body.shippingAddress.province + data.body.shippingAddress.city + data.body.shippingAddress.county + data.body.shippingAddress.address +'</dd>';

    if(data.body.shippingAddress.postCode !== ""){
        html+='<dt>邮政编码：</dt>';
        html+='<dd class="address-postCode">'+ data.body.shippingAddress.postCode +'</dd>';
    }



    html+='</dl>';
    html+='</div>';
    return html;

}




/**
 * 订单详情 -- 生成收货地址信息
 * @param data
 * @returns {string}
 */
function getStateAddressInfo(data){
    var html="";
    html+='<div class="orders-address-infor">';
    html+=' <dl class="orders-address-inforlist">';
    html+='<dt>收货人：</dt>';
    html+='<dd> ' + data.body.shippingAddress.consignee + ' <span class="address-phone">'+ data.body.shippingAddress.phone +'</span></dd>';
    html+='<dt>收货地址：</dt>';
    html+='<dd class="address-addr">'+ data.body.shippingAddress.province + data.body.shippingAddress.city + data.body.shippingAddress.county + data.body.shippingAddress.address +'</dd>';
    html+='<dt>邮政编码：</dt>';
    html+='<dd class="address-postCode">'+ data.body.shippingAddress.postCode +'</dd>';
    html+='</dl>';
    html+='</div>';

    return html;

}











/**
 * 订单详情 -- 生成物流信息
 * @param data
 * @param states
 * @returns {string}
 */
function getStateTransport( data,data2 ){
    var html='';
    var state = data2.body.orderState.replace(/\s+/g, "").split("");
    if( parseInt(state[0]) !== 0 || parseInt(state[1]) !== 0 ) {
        html += '<div class="orders-myorder-logistics">';
        html += '<div class="myorder-logistics-nav">  <span class="myorder-logistics-title">订单跟踪</span> <i class="myorder-logistics-arrow logistics-arrowD"></i> </div>';
        html += ' <div class="myorder-logistics-box"> <div class="myorder-logistics-infor">';

        /*        html += '<dl class="orders-address-inforlist">';
         html += ' <dt>物流状态：</dt><dd class="state-active">暂无</dd>';
         html += '<dt>快递公司：</dt><dd>' + (data2.body.expressCompany ? data2.body.expressCompany : "匹配中") + '</dd>';
         html += '<dt>运单号：</dt><dd>' + (data2.body.expressNumber ? data2.body.expressNumber : "") + '</dd></dl>';
         html += '</div>';*/

        html += '<div class="myorder-logistics-pos">';
        html += '<ul class="orderdetail-logistics-list">';
        for (var i = 0; i < data.body.length; i++) {
            html += '<li class="line active"><p>' + data.body[i].message + '</p><p> ' + data.body[i].time + ' </p></li>';
        }
    }
    html+='</ul>';
    html+='</div>';
    html+='</div>';
    html+='</div>';

    return html;

}


/**
 * 订单行情 --- 生成主体区域的头部banner
 * @param data
 * @returns {string}
 */
function getStateBanner( data ){
    var html='';
    //var state = data.body.orderState.replace(/\s+/g, "").split("");
    var state = data.orderState;

    if( !is_refund(state) ){
        if(state == judgeOrderState.normal.notPay ){
            html += '<div class="orders-details-state details-state-bg-waitpay">';
            html += '<h3 class="details-state-title">' + data["stateText"] + '</h3>';
            html += '</div>';
        }

        if( state == judgeOrderState.normal.waltGood ){
            html += '<div class="orders-details-state details-state-bg-waitpay">';
            html += '<h3 class="details-state-title">' + data["stateText"] + '</h3>';
            html += '</div>';
        }

        if(  state == judgeOrderState.normal.shipped  ){
            html += '<div class="orders-details-state details-state-bg-ship">';
            html += '<h3 class="details-state-title">' + data["stateText"] + '</h3>';
            html += '</div>';
        }
        if( state == judgeOrderState.normal.received ){

            html += '<div class="orders-details-state details-state-bg-success">';
            html += '<h3 class="details-state-title">' + data["stateText"] + '</h3>';
            html += '</div>';
        }
        if( state == judgeOrderState.cancel.canceled ){

            html += '<div class="orders-details-state details-state-bg-success">';
            html += '<h3 class="details-state-title">' + data["stateText"] + '</h3>';
            html += '</div>';
        }




    }else{


    }

    return html;
}










/**
 * 订单详情 -- 生成底部支付状态操作
 * @param data
 * @returns {string}
 */
function getStateOperate( data ){
    var html='';
    //var state = data.body.orderState.replace(/\s+/g, "").split("");
    var state = data.body.orderState;

    if( !is_refund(state) ){
        if(state == judgeOrderState.normal.notPay ){
            // html+= ' <span class="orders-operate-zfb">支付宝支付</span>';
            html+= '<span class="orders-operate-wx">微信支付</span>';
            html+= '<span class="orders-operate-cancel">取消订单</span>';
        }

        if( state == judgeOrderState.normal.waltGood ){
            //html+= '<span class="orders-operate-refund">申请退款</span>';
            html+='<span class="orders-operate-sure">确认收货</span>';
        }

        if(  state == judgeOrderState.normal.shipped  ){
            html+= '<span class="orders-operate-refund">申请退款</span>';
            html+= '<span class="orders-operate-delete">删除订单</span>';
        }
        if( state == judgeOrderState.normal.received ){
            html+= '<span class="orders-operate-delete">删除订单</span>';
        }
        if( state == judgeOrderState.cancel.canceled ){

            html+= '<span class="orders-operate-delete">删除订单</span>';
        }

    }else{


    }

    return html;

}



/**
 * 订单详情 -- 生成商品详情列表信息
 * @param data
 * @returns {string}
 */







function getStateGood(data){
    console.log(data);
    var html="";
    var state = data["orderState"];

    html+='<div class="orders-myorder-item"  data-orderId="' + data.orderId + '">';
    html+='<div class="card">';
    html+='<div class="card-header ordersItem-dt"   data-orderId="' + data.orderId + '">';
    // html+='<a href="/api/store/page/orders/ordersDetails">';
    html+='<span>' + data.createTime  + '</span>';
    html+='<span class="orders-myorder-state">' + data["stateText"]  + '</span>';
    // html+='</a>';
    html+='</div>';
    html+='<div class="card-content">';
    html+='<div class="list-block media-list">';
    html+="<ul>";
    for( var j = 0; j < data.orderGoodsList.length;j++ ) {
        /*            html+="<li>";
         html += '<div class="item-content">';
         html += '<div class="item-media">';
         html += '<img src="' + data.orderGoodsList[j].goodsImage + '" >';
         html += '</div>';
         html += '<div class="item-inner">';
         html += '<div class="item-title-row">';
         html += '<div class="item-title">' + data.orderGoodsList[j].goodsTitle + '</div>';
         html += '</div>';
         html += '<div class="item-subtitle">';
         html += '<span class="price">￥' + data.orderGoodsList[j]["goodsPrice"] + '</span>';
         html += '<span>×' + data.orderGoodsList[j]["goodsNumber"] + '</span>';
         html += '</div>';
         html += '</div>';
         html += '</div>';
         html+="</li>";*/
        var goodsMsg = {
            orderId : data.orderId,
            goodsId : data.orderGoodsList[j]["goodsId"],
            goodsNumber :data.orderGoodsList[j]["goodsNumber"]
        }

        html+='<li class="" goodsMsg=\'' + JSON.stringify(goodsMsg) + '\' orderRefundId="' + (data.orderGoodsList[j]["orderRefundId"] ? data.orderGoodsList[j]["orderRefundId"] : "") + '">';
        html += '<div class="item-content">';
        html += '<div class="item-media">';
        html += '<img src="' + data.orderGoodsList[j].goodsImage + '" >';
        html += '</div>';
        html += '<div class="item-inner">';


        html += '';
        html += '';
        html += '<div class="orders-myorder-msg">';
        html += '<div class="item-title-row">';
        html += '<div class="item-title">' + data.orderGoodsList[j].goodsTitle + '</div>';
        html += '</div>';

        html += '<div class="item-subtitle">';
        html += '<span class="price">￥' + data.orderGoodsList[j].goodsPrice + '</span>';
        html += '<span>×' + data.orderGoodsList[j].goodsNumber + '</span>';
        html += '</div>';
        html += '</div>';
        html += '<div class="orders-myorder-oper">';

        if(data.orderGoodsList[j]["canTuihuo"]){

            html += '<span class="orders-operate-refunds">退货</span>';
        }else if(data.orderGoodsList[j]["canWanshan"]){
            html += '<span class="orders-operate-refundedit">完善退货信息</span>';
        }else if(data.orderGoodsList[j]["canCancelRefundGoods"]){
            html += '<span class="orders-operate-refundCancel">取消退货</span>';
        }

        // else{

        html += '<span class="audit">' + (data.orderGoodsList[j]["stateText"] ? data.orderGoodsList[j]["stateText"] : "") + '</span>';
        // }



        html += '</div>';


        html += '</div>';
        html += '</div>';
        html += '<div class="">';

        html += '</div>';

        html+="</li>";
    }
    html+="</ul>";
    html+='<div class="orders-payinfor-infor">';
    html+='共<span class="pay-num">' + data.orderGoodsTotal + '</span>件商品 &nbsp;&nbsp;';
    html+=' 合计：<span class="pay-total">￥' + data.orderPrice + '</span>'+ '（运费：' + data.orderFreight+'）';
    html+='</div>';
    html+='</div>';

    html+='</div>';

    html+='</div>';
    html+='</div>';



    return html;
}



function getStateRefundBanner(data){

    var html="";

    if(data.body.orderState == judgeOrderState.refund.checking ){

        html += '<div class="orders-details-state details-state-bg-check-refuse">';
        html += '<h3 class="details-state-title">审核中</h3>';
        //html+='<p>原因：包装已拆，认证卡已认证</p>';
        html += '</div>';

    }
    if( data.body.orderState == judgeOrderState.refund.checkNotPass ){

        html += '<div class="orders-details-state details-state-bg-check-refuse details-state-txtstyle">';
        html += '<h3 class="details-state-title">审核未通过</h3>';
        html+='<p>' + (data.body.message ?  "原因：" + data.body.message : "" ) + '</p>';
        html += '</div>';

    }

    if(data.body.orderState == judgeOrderState.refund.checkpass){

        html += '<div class="orders-details-state details-state-bg-refund details-state-txtstyle">';
        html += '<h3 class="details-state-title">审核通过</h3>';
        html+='<p>请点击下方\"填写退货信息\"按钮上传退货物流信息</p>';
        html += '</div>';

    }

    if(data.body.orderState == judgeOrderState.refund.receiptSuring){

        html += '<div class="orders-details-state details-state-bg-refund details-state-txtstyle">';
        html += '<h3 class="details-state-title">退货中</h3>';
        html+='<p>请您耐心等待，我们将在收到快递的第一时间联系您！</p>';
        html += '</div>';

    }


    return html;
}


function getStateRefundfooter(data){
    var html="";

    if(data.body.orderState == judgeOrderState.refund.checking ){

        html+= '<span class="orders-operate-cancelRefund">取消退款</span>';

    }
    if( data.body.orderState == judgeOrderState.refund.checkNotPass ){

        html+= '<span class="orders-operate-againApply">再次申请</span>';
        html+= '<span class="orders-operate-delete">删除订单</span>';


    }

    if(data.body.orderState == judgeOrderState.refund.checkpass){

        html+= '<span class="orders-operate-addrefund">填写退货信息</span>';

    }


    return html;
}










function getOrderListbanner(data){

    var html="";

    if(data.body.orderState == judgeOrderState.refund.checking ){

        html += '<span class="orders-myorder-state">审核中</span>';

    }
    if( data.body.orderState == judgeOrderState.refund.checkNotPass ){


        html += '<span class="orders-myorder-state">审核未通过</span>';

    }

    if(data.body.orderState == judgeOrderState.refund.checkpass){

        html += '<span class="orders-myorder-state">审核通过</span>';
    }

    if(data.body.orderState == judgeOrderState.refund.receiptSuring){
        html += '<span class="orders-myorder-state reGood">退货中</span>';
    }


    return html;
}

/**
 * 订单列表 -- 支付状态
 * @param data
 * @returns {string}
 */
function payState( data ){
    var html = "";
    for(var i = 0; i < data.length;i++){

        //var state = data[i].orderState.replace(/\s+/g,"").split("");
        var state = data[i].orderState;
        html+='<div class="orders-myorder-item"  data-orderId="' + data[i].orderId + '">';
        html+='<div class="orders-myorder-details">';
        html+='<div class="orders-myorder-nav">';
        html+='<span class="orders-myorder-time">' + data[i].createTime + '</span>';
        html+= '<span class="orders-myorder-state">' + data[i]["stateText"] + '</span>';

        html+='</div>';

        for( var j = 0; j < data[i].orderGoodsList.length;j++ ){

            html+='<div class="orders-list-item clearfix">';
            html+='<div class="items-img left">';
            html+='<img src="' + data[i].orderGoodsList[j].goodsImage + '" />';
            html+=' </div>';
            html+='<div class="items-infor right">';
            html+='<h4>' + data[i].orderGoodsList[j].goodsTitle + '</h4>';
            html+='<div class="items-others clearfix">';
            html+='<span class="itmes-price">￥' + data[i].orderGoodsList[j].goodsPrice + '</span>';
            html+='<span class="itmes-number right"> ×' + data[i].orderGoodsList[j].goodsNumber + ' </span>';
            html+='</div>';
        }


        html+='</div>';
        html+='</div>';
        html+='<div class="orders-payinfor-infor">';
        html+='共<span class="pay-num">' + '' + '</span>件商品 &nbsp;&nbsp;';
        html+=' 合计：<span class="pay-total">￥' + data[i].orderPrice + '</span>(运费包邮)';
        html+='</div>';

        html+='</div>';
        html+='<div class="orders-myorder-operate">';



        if( !is_refund(state) ){
            if(state == judgeOrderState.normal.notPay ){
                html+='<span class="orders-operate-pay">去支付</span>';
                html+='<span class="orders-operate-cancel">取消订单</span>';
            }

            if( state == judgeOrderState.normal.waltGood ){
                //html+= '<span class="orders-operate-refund">申请退款</span>';
                html+='<span class="orders-operate-sure">确认收货</span>';
            }

            if(  state == judgeOrderState.normal.shipped  ){
                html+= '<span class="orders-operate-refund">申请退款</span>';
                html+= '<span class="orders-operate-delete">删除订单</span>';
            }
            if( state == judgeOrderState.normal.received ){
                html+= '<span class="orders-operate-delete">删除订单</span>';
            }
            if( state == judgeOrderState.cancel.canceled ){

                html+= '<span class="orders-operate-delete">删除订单</span>';
            }

        }

        html+='</div>';
        html+='</div>';
    }
    return html;

}


/**
 *  页面中事件处理函数
 */
/**
 * 收货地址页面的相关操作
 */

function dealAddressList(){
    // 收货地址删除操作
    $('.orders-addroper-delete').each(function(){
        $(this).on('touchstart',function(){
            var addrId = $(this).parents('.orders-address-item').attr("data-addId");
            var obj = {
                body : {
                    addressId:addrId
                }
            };
            addressDelete(obj,function(data){

            });
            $(this).parents('.orders-address-item').remove();
        })
    });
    // 收货地址设置默认地址
    $('.orders-addr-default').each(function(){

        $(this).on('touchstart',function(){

            var addressId = $(this).parents('.orders-address-item').attr("data-addId");

            if( $(this).hasClass('active') ){

                $(this).removeClass('active');

            }else{

                $('.orders-addr-default').removeClass('active');
                $(this).addClass('active');

                addressSetDefault( {body:{addressId:addressId}},function(data){
                    console.log(data);

                });
            }
        });
    });

    //  收货地址编辑
    $('.orders-addroper-edit').each(function(){
        $(this).on('touchstart',function(){
            var addrId = $(this).parents('.orders-address-item').attr("data-addId");
            var objPar = {
                addressId : addrId
            };
            window.location = "orders_address_edit.html" + urlPassVal(objPar);
        });
    })




    $('.orders-address-infor').each(function(){
        $(this).on("click",function(){

            var obj = {

                body: {
                    addressId : $(this).parents(".orders-address-item").attr("data-addid"),
                    consignee : $(this).find(".addr-name").text(),
                    phone : $(this).find(".addr-phone").text(),
                    province : "",
                    city : "",
                    county : "",
                    address : $(this).find(".addr-detail").text(),
                    postCode : $(this).find(".addr-postcode").text()
                }
            }

            window.parent.$('.orders-address-infobox').html("");
            window.parent.$('.orders-address-infobox').html( AddressValInOk( obj ) );
            window.parent.$("#seleteGoods").css({"left":"100%"});


        })

    })



}



function getVerifyCodes(obj){

    getVerifyCode(obj,function(data){
        if(data.head.code===1){

        }else {
            $.toast(data.head.message)
        }

    })
}








/**
 * 功能性函数集合
 */



/**
 * 对手机号中间四位进行*化
 * @param phone
 * @returns {XML|void|*|string}
 */
function replacePhoneNumber( phone ){
    return phone.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2")
}

/**
 * 获取select 选中的值
 * @param id
 * @returns {*}
 */
function selectValue(id){
    var obj = document.querySelector("" + id ); //定位id

    var index = obj.selectedIndex; // 选中索引

    var text = obj.options[index].text; // 选中文本

    var value = obj.options[index].value; // 选中值

    return value;
}

/**
 * 手机号码格式验证函数
 * @param mobile
 * @returns {boolean}
 */
function validatemobile(mobile){
    if(mobile.length!=11 ){
        return false;
    }
    else{
        return true;
    }
}




/**
 * 验证码格式验证函数
 * @param verify
 * @returns {boolean}
 */
function checkVerify( verify ){
    if(verify.length == 0 ){
        return false;

    }else{
        return true;
    }
}

/**
 * 密码格式验证函数
 * @param pswd
 * @returns {boolean}
 */
function checkPassword( pswd ){
    var reg = /^[a-zA-Z][a-zA-Z0-9_]{6,20}/
    if(reg.test(pswd) && pswd.length !=0 ){
        return true;
    }else{
        return false;
    }
}


/**
 * 密码
 * @type {number}
 */
var pad = 123456789;
/**
 * 在需要跳转的url上面附加参数以供下一级使用
 * @param obj
 * @returns {string}
 */
function urlPassVal(obj){
    var str = encodeURI(JSON.stringify(obj));
    str = encrypt(str,pad );
    return "?msg=" +  str;
}

/**
 * 获取url上面的参数
 */
function getUrlEn() {

    var par = window.location.search.replace(/\s+/g,"").replace(/\?msg=/ig,"");
    par = decrypt(par,pad);
    par = decodeURI(par);
    return JSON.parse(par);

}

function displayInNot(){
    var html='';
    html+='<div class="orders-null-container">';
    html+='<img class="orders-null-img404" src="/static/store/images/orders/orders_null.png" />';
    // html+='<h3 class="orders-null-tip">您购物车空空的哦!</h3>';
    // html+='<span class="orders-null-go">去逛逛</span>';
    html+='</div>';
    return html;
}


/**
 * DES加密函数
 * @param str
 * @param pwd
 * @returns {*}
 */

//str 是想加密的字符串
//pwd 是key
function encrypt(str, pwd) {
    if (pwd == null || pwd.length <= 0) {
        alert("Please enter a password with which to encrypt the message.");
        return null;
    }
    var prand = "";
    for (var i = 0; i < pwd.length; i++) {
        prand += pwd.charCodeAt(i).toString();
    }
    var sPos = Math.floor(prand.length / 5);
    var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) + prand.charAt(sPos * 4) + prand.charAt(sPos * 5));
    var incr = Math.ceil(pwd.length / 2);
    var modu = Math.pow(2, 31) - 1;
    if (mult < 2) {
        alert("Algorithm cannot find a suitable hash. Please choose a different password.  Possible considerations are to choose a more complex or longer password.");
        return null;
    }
    var salt = Math.round(Math.random() * 1000000000) % 100000000;
    prand += salt;
    while (prand.length > 10) {
        prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
    }
    prand = (mult * prand + incr) % modu;
    var enc_chr = "";
    var enc_str = "";
    for (var i = 0; i < str.length; i++) {
        enc_chr = parseInt(str.charCodeAt(i) ^ Math.floor((prand / modu) * 255));
        if (enc_chr < 16) {
            enc_str += "0" + enc_chr.toString(16);
        } else {
            enc_str += enc_chr.toString(16);
        }
        prand = (mult * prand + incr) % modu;
    }
    salt = salt.toString(16);
    while (salt.length < 8) {
        salt = "0" + salt;
    }
    enc_str += salt;
    return enc_str;
}


/**
 * DES解密
 * @param str   解密的字符串
 * @param pwd    密码
 * @returns {string}
 */
function decrypt(str, pwd) {
    if (str == null || str.length < 8) {
        alert("A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted.");
        return;
    }
    if (pwd == null || pwd.length <= 0) {
        alert("Please enter a password with which to decrypt the message.");
        return;
    }
    var prand = "";
    for (var i = 0; i < pwd.length; i++) {
        prand += pwd.charCodeAt(i).toString();
    }
    var sPos = Math.floor(prand.length / 5);
    var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) + prand.charAt(sPos * 4) + prand.charAt(sPos * 5));
    var incr = Math.round(pwd.length / 2);
    var modu = Math.pow(2, 31) - 1;
    var salt = parseInt(str.substring(str.length - 8, str.length), 16);
    str = str.substring(0, str.length - 8);
    prand += salt;
    while (prand.length > 10) {
        prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
    }
    prand = (mult * prand + incr) % modu;
    var enc_chr = "";
    var enc_str = "";
    for (var i = 0; i < str.length; i += 2) {
        enc_chr = parseInt(parseInt(str.substring(i, i + 2), 16) ^ Math.floor((prand / modu) * 255));
        enc_str += String.fromCharCode(enc_chr);
        prand = (mult * prand + incr) % modu;
    }
    return enc_str;
}

function reFalse(){
    return false;
}


function is_weixin(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
var paySuccessI;
var a = 1;
function buildModal(img,orderId){
    var html="";
    html+='<div class="popup popup-toPay">';
    html+='<span class="close-popup colseBuildModal">关闭</span>';
    html+='<div class="content-block">';
    html+='<div class="ewm">';
    html+="";
    html+= '<img src=\'' + img + '\' />';
    html+='</div>';
    html+='<p class="text">请使用微信扫码支付</p>';
    html+='</div>';
    html+='</div>';

    $.popup(html,true);
    paySuccessI=setInterval(function () {
        queryIsPaySuccess({body:{orderId:orderId}},function (data) {
            if(data.head.code=1){
                if(data.body==true){
                    clearInterval(paySuccessI);
                    window.location=getHost()+"/api/store/page/orders/orderList";

                }else{
                    console.log("还没支付")
                }

            }

        })
    }, 2000);

}

$(document).on("click",".colseBuildModal",function () {
    clearInterval(paySuccessI);
    window.location=getHost()+"/api/store/page/orders/orderList";
})

/*$(".colseBuildModal").click(function () {
 clearInterval(paySuccessI);
 })*/

function queryIsPaySuccess(obj,callback){
    var dirtPay = {
        url : getHost()+"/api/store/order/see/ispay?msg=",
        success : function(data){
            callback(data);
        },
        error:function(){

        }
    };
    var objects = {
        head : {
            crossDomain : "cross_payquery"
        }
    };
    objects.head = obj.head ?  obj.head : objects.head;
    objects.body = obj.body ? obj.body : {};
    var req = RequestData( objects );
    req.getAjax( dirtPay );
}

/* - - */

var Todo = function () {
    this.number = 1;
    this.goodsType = 0;
};

Todo.prototype.add = function () {

    return this.number++;

};
Todo.prototype.sub = function () {
    if(this.number === 1){
        return false;
    }
    return this.number--;
};
Todo.prototype.rand = function (number) {
    number = parseInt(number);
    this.number = number;
    return this.number;

};
Todo.prototype.getNumber = function () {
    return this.number;
};

Todo.prototype.setBuy = function () {
    this.goodsType=0;
    return  this.goodsType;
};

Todo.prototype.setTaste = function () {
    this.goodsType=1;
    return  this.goodsType;
}

Todo.prototype.getGoodsType = function () {
    return  this.goodsType;
}